import asyncio

import motor.motor_asyncio
from bson import ObjectId
from fastapi import FastAPI

# uvicorn main:app --reload --host=0.0.0.0 --port=8001
app = FastAPI(title="Tortoise ORM FastAPI example")

collectiondb = motor.motor_asyncio.AsyncIOMotorClient('mongodb://cjrw:vipdatacenter@192.168.31.166:27017/collection')

db = collectiondb.collection
db.auth()

# async def do_search():
#     user = await collectiondb.collection.jss_w_f_panternt_page.find_one({"_id": ObjectId("5ea525b4c3e35afc6e1d3593")})
#     print(user)
#
# async def do_search2():
#     user = await collectiondb.collectiondb.list_database_names()
#     print(user)
#
#
# loop = asyncio.get_event_loop()
# loop.run_until_complete(do_search2())

# client66 =  motor.motor_asyncio.AsyncIOMotorClient('mongodb://root:vipdatacenter@192.168.31.168:27017')
#
# client68 = motor.motor_asyncio.AsyncIOMotorClient('mongodb://192.168.31.168:27017')

@app.get("/test/search")
async def wfjournalpageid():
    print("************")
    user = await collectiondb.collection.jss_w_f_panternt_page.find_one({"_id": ObjectId("5ea525b4c3e35afc6e1d3593")})
    print("************")
    print(type(user))
    del user["_id"]
    return user
